//
//  XLStatusToolbar.swift
//  XLVeibo
//
//  Created by macbook on 16/6/29.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

class XLStatusToolbar: UIView {

    var retweetButton: UIButton?
    var commentButton: UIButton?
    var unlikeButton: UIButton?
    
    
   //恭外界赋值
    var status:XLStatus?{
    
        didSet{
        
            retweetButton?.setTitle(status?.repostsStr, forState: UIControlState.Normal)
            commentButton?.setTitle(status?.commentsStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(status?.attitudesStr, forState: UIControlState.Normal)
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
     
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    private func setupUI(){
        
        retweetButton = addBnt("timeline_icon_retweet", title: "转发")
        commentButton = addBnt("timeline_icon_comment", title: "评论")
        unlikeButton = addBnt("timeline_icon_unlike", title: "赞")

        
        //分割线
        let line1 = setImage()
        let  line2 = setImage()
        
        retweetButton?.snp_makeConstraints(closure: { (make) in
            
            make.top.left.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        })
        
        commentButton?.snp_makeConstraints(closure: { (make) in
            
            make.top.bottom.equalTo(self)
            make.left.equalTo((retweetButton?.snp_right)!)
            make.width.equalTo(unlikeButton!)
        })
        
        unlikeButton?.snp_makeConstraints(closure: { (make) in
            
            make.right.top.bottom.equalTo(self)
            make.left.equalTo((commentButton?.snp_right)!)
        })
        
        line1.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo((retweetButton?.snp_right)!)
        }
        
        line2.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo((commentButton?.snp_right)!)
        }
        
        
        
        
    }
    
    
    //行为需要设置btn的位置，所以要返回值
    private func addBnt(imageName:String,title:String)->UIButton{
    
        let btn = UIButton()
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        btn.setTitleColor(UIColor.darkTextColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        //添加控件
        addSubview(btn)
        
        return btn
        
    }
    
    
    //中间的线
    private func setImage()->UIImageView{
    
        let image = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(image)
        
        return image
    }
    
    
    
    
    
}





